-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix custom status label bug #555
Conversation
Note that we need to test these changes with the Classic Editor as well. |
Aside: we should revert the changes to package-lock.json, since those aren't necessary for this PR. |
Tested on site with block editor enabled for posts and can confirm this branch addresses issue described in #553. Also confirmed the I also tested with post type that does not have block editor enabled but does have custom statuses enabled. Can confirm that bugs with scheduling and trashing posts does not seem to be present on |
'name' => esc_js( $status->name ), | ||
'slug' => esc_js( $status->slug ), | ||
'description' => esc_js( $status->description ), | ||
$all_statuses = array_merge( $custom_statuses, $this->get_default_statuses() ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to abstracting this into get_default_statuses()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still kinda confusing, but hoping to move in the right direction
* The default statuses from core. Returned as an array of stdClass to | ||
* make it easy to merge with our custom statuses (which are WPTerm objects) | ||
* | ||
* return array an array of stdClass objects |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing @
in return
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good catch
blocks/src/custom-status/block.js
Outdated
// Gutenberg will also override the status set in '.editor-post-save-draft' after save, and there isn't yet a way | ||
// to subscribe to a "post save" message. So instead set a timeout and override the text in '.editor-post-save-draft' | ||
let schedulePostStatusUpdater = () => { | ||
setTimeout(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potentially a more "native" way of doing this would be to monitor for changes to the modified time (set modified time on load and compare/update/fire action in wp.data.subscribe
callback).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, not a bad thought, I'll mess around and see if I can get that working
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though I'm not sure it'll solve the underlying issue. We can observe post update, but the problem is here.
Gutenberg is setting a timeout of 1s to flip the message from "Saving..." to the original text: "Save as Draft|Pending
". But if there's concern over about polling, we could set one timeout for something like 1.2s and that might solve it (but small race condition)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get what you mean. The two options you proposed (callback loop and timeout after save) make sense to me based on current Gutenberg code. This seems like it could also be a good place for an upstream change to Gutenberg if there's a filter that could make it work. Best idea I have right now would be providing a way to filter/bring your own function to use instead of isPending ? __( 'Save as Pending' ) : __( 'Save Draft' );
$scheduled_status->name = __( 'Scheduled', 'edit-flow' ); | ||
$scheduled_status->slug = 'future'; | ||
$scheduled_status->description = ''; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor but might be an extra linebreak here?
return [ $published_status, $private_status, $scheduled_status ]; | ||
} | ||
|
||
/*** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor but maybe an extra asterisk here?
@@ -452,7 +434,7 @@ function post_admin_header() { | |||
// Now, let's print the JS vars | |||
?> | |||
<script type="text/javascript"> | |||
var custom_statuses = <?php echo json_encode( $all_statuses ); ?>; | |||
var custom_statuses = JSON.parse( decodeURIComponent( '<?php echo rawurlencode( wp_json_encode( $statuses_js ) ); ?>' ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems overly complex? Why do we need multiple levels of encoding and decoding?
If there's a valid reason, we should note that in an inline comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, but it's in the suggested VIP code sample for encoding JSON. Down to move it back to just wp_json_encode
if no concerns there
blocks/src/custom-status/block.js
Outdated
} | ||
|
||
schedulePostStatusUpdater(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit worried out the unwanted (and unexpected) effects of having an infinite loop to fix the label bug (i.e. where the save button occasionally flips to "Save Draft" after saving).
It would be better to keep the change to have the save button as generic as possible (i.e. "Save") and live with the occasional text flip. And then work with the Gutenberg project to find a better way to fix this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, maybe there's a better way to approach this while waiting for Gutenberg, I'll mess around a bit. Just seems like a point of confusion for consumers
@cojennin I have a much simpler fix in #556 that I'm going to push out. I'm going to keep this open as I think it's worth iterating on to improve the the "Save" button behavior as it's definitely not ideal right now (@davisshaver's idea is worth exploring, for example). |
Yea, an upstream change to Gutneberg would definitely be preferred (less
work for us!).
In the meantime, there might be a better way than this infinite polling
approach, it’s worth hacking around on to see what we can do
…On Mon, Nov 25, 2019 at 7:38 AM Davis Shaver ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In blocks/src/custom-status/block.js
<#555 (comment)>:
>
// Hack :(
// @see WordPress/gutenberg#3144
-let <WordPress/gutenberg#3144-let> sideEffectL10nManipulation = status => {
- let node = document.querySelector('.editor-post-save-draft');
- if ( node ) {
- document.querySelector( '.editor-post-save-draft' ).innerText = `${ __( 'Save' ) }`
- }
+// Gutenberg will also override the status set in '.editor-post-save-draft' after save, and there isn't yet a way
+// to subscribe to a "post save" message. So instead set a timeout and override the text in '.editor-post-save-draft'
+let schedulePostStatusUpdater = () => {
+ setTimeout(() => {
I get what you mean. The two options you proposed (callback loop and
timeout after save) make sense to me based on current Gutenberg code. This
seems like it could also be a good place for an upstream change to
Gutenberg if there's a filter that could make it work. Best idea I have
right now would be providing a way to filter/bring your own function to use
instead of isPending ? __( 'Save as Pending' ) : __( 'Save Draft' );
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#555?email_source=notifications&email_token=AAOM7GCHGWNJBY3MJJO6UKLQVPBMXA5CNFSM4JPZJQAKYY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCM2RO5I#discussion_r350158817>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAOM7GGV2FEQOBKF6NVKVUTQVPBMXANCNFSM4JPZJQAA>
.
|
1770fc4
to
09a399b
Compare
@mjangda @davisshaver doesn't seem like there's a real clean way to overcome Gutenberg explicitly setting I was thinking we might be able to use a MutationObserver instead of polling, but browser support isn't great (see IE), and the shim I found effectively does exactly what this PR does now (set's a timeout to observer a DOM change). I added an It would be great to get a fix into Gutenberg core for this issue, but in the meantime it'd be great to solve this for Edit Flow users. The behaviour we have now, where the text flips from "Save" to "Save Draft" after a user clicks save, regardless of status, is confusing. |
I dropped an issue into Gutenberg, linking here for visibility: WordPress/gutenberg#18743 |
09a399b
to
410f4f0
Compare
@mjangda @davisshaver I've updated this PR with some e2e testing to verify the PR works as expected, let me know how're you're feeling about it. I'm a little more confident now that it'll work as expected |
23e0a65
to
046814c
Compare
Closing in favor of #585 |
We should be using the status in the
Save as
section of the Gutenberg editor. This change will add the status to theSave as
section when a user saves the post with a custom status. There's currently no way to hook into core to do this, so we have a timeout to correct the status once it's set by core.To validate status being set